/*
 * ZonalAdd.java
 *
 * Created on February 16, 2005, 2:22 PM
 */
package edu.temple.GUS.MMA.Functions;

import edu.temple.GUS.MMA.DataTypes.*;
import edu.temple.GUS.MMA.Neighborhoods.*;
import edu.temple.GUS.MMA.Exceptions.MMAFunctionInitException;
import edu.temple.GUS.MMA.io.*;
import java.util.*;
import java.io.*;
import edu.temple.GUS.MMA.Functions.ZonalLoop;
import edu.temple.GUS.MMA.Functions.ZonalFunctions;
/**
 *
 * @author  rkhanna
 */
public class ZonalAdd {
    
    /** Creates a new instance of ZonalAdd */
    public ZonalAdd() 
    {   }        
    
     
    public MMATimeSeries initTS1()
    {
        MMATimeSeries tsobj = new MMATimeSeries();
        int T=6;
        int tResolution=5;        
        float arr[]={3,2,1,3,2,1};
        int noData = 9999;
        tsobj.putT(T);
        tsobj.putTResolution(tResolution);        
        tsobj.putData(arr);
        tsobj.putNoData(noData);
        return tsobj ;
    }
        
    public MMATimeSeries initTS2()
    {
        MMATimeSeries tsobj = new MMATimeSeries();
        int T=6;
        int tResolution=6;        
        float arr[]={1,1,1,1,1,1};
        int noData = 9999;
        tsobj.putT(T);
        tsobj.putTResolution(tResolution);        
        tsobj.putData(arr);
        tsobj.putNoData(noData);
        return tsobj ;
    }

    public MMAGrid initGrid1()
    {
        MMAGrid grid1 = new MMAGrid();
        int X = 3;
        int Y = 4;
        int tResolution=5;        
        float arr[][]={
                    {1,2,3,4},
                    {1,2,3,4},
                    {1,2,3,4},
                    };
        int noData = 9999;
        grid1.putX(X);
        grid1.putY(Y);        
        grid1.putData(arr);
        grid1.putNoData(noData);
        return grid1;
    }
    
    public MMAGrid initGrid2()
    {
        MMAGrid grid1 = new MMAGrid();
        int X = 3;
        int Y = 4;
        int tResolution=5;        
        float arr[][]={
                    {4,3,2,1},
                    {4,3,2,1},
                    {4,3,2,1},
                    };
        int noData = 9999;
        grid1.putX(X);
        grid1.putY(Y);        
        grid1.putData(arr);
        grid1.putNoData(noData);
        return grid1;
    }

    public MMASpaceCube initSpaceCube1()
    {
        MMASpaceCube sCube1 = new MMASpaceCube();
        int X = 3;
        int Y = 4;
        int Z = 5;        
        float arr[][][] =  new float[Z][Y][X];                
        int tResolution=5;        
        int noData = 9999;
            for(int k=0;k<Z;k++)
                for(int j=0;j<Y;j++)
                    for(int i=0;i<X;i++)
                        arr[k][j][i]=i+1;
        sCube1.putX(X);
        sCube1.putY(Y);        
        sCube1.putZ(Z);                
        sCube1.putData(arr);
        sCube1.putNoData(noData);
        return sCube1;
    }
    
    public MMASpaceCube initSpaceCube2()
    {
        MMASpaceCube sCube1 = new MMASpaceCube();
        int X = 3;
        int Y = 4;
        int Z = 5;        
        float arr[][][] =  new float[Z][Y][X];                
        int tResolution=5;        
        int noData = 9999;
            for(int k=0;k<Z;k++)
                for(int j=0;j<Y;j++)
                    for(int i=0;i<X;i++)
                        arr[k][j][i]=i+1;
        sCube1.putX(X);
        sCube1.putY(Y);        
        sCube1.putZ(Z);                
        sCube1.putData(arr);
        sCube1.putNoData(noData);
        return sCube1;
    }

    public MMATimeCube initTimeCube1()
    {
        MMATimeCube tCube1 = new MMATimeCube();
        int X = 3;
        int Y = 4;
        int T = 5;        
        float arr[][][] =  new float[T][Y][X];                
        int tResolution=5;        
        int noData = 9999;
            for(int k=0;k<T;k++)
                for(int j=0;j<Y;j++)
                    for(int i=0;i<X;i++)
                        arr[k][j][i]=i+1;
        tCube1.putX(X);
        tCube1.putY(Y);        
        tCube1.putT(T);                
        tCube1.putData(arr);
        tCube1.putNoData(noData);
        return tCube1;
    }
    
    public MMATimeCube initTimeCube2()
    {
        MMATimeCube tCube1 = new MMATimeCube();
        int X = 3;
        int Y = 4;
        int T = 5;        
        float arr[][][] =  new float[T][Y][X];                
        int tResolution=5;        
        int noData = 9999;
            for(int k=0;k<T;k++)
                for(int j=0;j<Y;j++)
                    for(int i=0;i<X;i++)
                        arr[k][j][i]=3-i;
        tCube1.putX(X);
        tCube1.putY(Y);        
        tCube1.putT(T);                
        tCube1.putData(arr);
        tCube1.putNoData(noData);
        return tCube1;
    }
    
    public MMAHyperCube initHyperCube1()
    {
        MMAHyperCube tCube1 = new MMAHyperCube();
        int X = 3;
        int Y = 4;
        int Z = 5;        
        int T = 6;                
        float arr[][][][] =  new float[T][Z][Y][X];                
        int tResolution=5;        
        int noData = 9999;
            for(int l=0;l<T;l++)
                for(int k=0;k<Z;k++)
                    for(int j=0;j<Y;j++)
                        for(int i=0;i<X;i++)
                            arr[l][k][j][i]=i+1;
        tCube1.putX(X);
        tCube1.putY(Y);        
        tCube1.putZ(Z);        
        tCube1.putT(T);                
        tCube1.putData(arr);
        tCube1.putNoData(noData);
        return tCube1;
    }

    public MMAHyperCube initHyperCube2()
    {
        MMAHyperCube tCube1 = new MMAHyperCube();
        int X = 3;
        int Y = 4;
        int Z = 5;        
        int T = 6;                
        float arr[][][][] =  new float[T][Z][Y][X];                
        int tResolution=5;        
        int noData = 9999;
            for(int l=0;l<T;l++)
                for(int k=0;k<Z;k++)
                    for(int j=0;j<Y;j++)
                        for(int i=0;i<X;i++)
                            arr[l][k][j][i]=i+1;
        tCube1.putX(X);
        tCube1.putY(Y);        
        tCube1.putZ(Z);        
        tCube1.putT(T);                
        tCube1.putData(arr);
        tCube1.putNoData(noData);
        return tCube1;
    }

    public Hashtable execute(MMATimeSeries tSeries1, MMATimeSeries tSeries2) throws MMAFunctionInitException
    {        
        ZonalLoop zonalobj = new ZonalLoop();
        Hashtable ht_multiple_val = zonalobj.loopTimeSeries_TimeSeries(tSeries1, tSeries2);
        ZonalFunctions funcobj = new ZonalFunctions();
        Hashtable ht_single_val = funcobj.calculateZonalAdd(ht_multiple_val);
        return ht_single_val;        
    }
    
    
    public Hashtable execute(MMATimeSeries tSeries, MMATimeCube tCube) throws MMAFunctionInitException
    {        
        ZonalLoop zonalobj = new ZonalLoop();
        Hashtable ht_multiple_val = zonalobj.loopTimeSeries_TimeCube(tSeries, tCube);        
        ZonalFunctions funcobj = new ZonalFunctions();
        Hashtable ht_single_val = funcobj.calculateZonalAdd(ht_multiple_val);
        return ht_single_val;        
    }
    
    
    public Hashtable execute(MMATimeSeries tSeries, MMAHyperCube hCube) throws MMAFunctionInitException    
    {        
        ZonalLoop zonalobj = new ZonalLoop();
        Hashtable ht_multiple_val = zonalobj.loopTimeSeries_HyperCube(tSeries, hCube);
        ZonalFunctions funcobj = new ZonalFunctions();
        Hashtable ht_single_val = funcobj.calculateZonalAdd(ht_multiple_val);
        return ht_single_val;                
    }
    
    public Hashtable execute(MMAGrid grid1, MMAGrid grid2) throws MMAFunctionInitException    
    {
        ZonalLoop zonalobj = new ZonalLoop();
        Hashtable ht_multiple_val = zonalobj.loopGrid_Grid(grid1, grid2);    
        ZonalFunctions funcobj = new ZonalFunctions();
        Hashtable ht_single_val = funcobj.calculateZonalAdd(ht_multiple_val);
        return ht_single_val;
    }        
   
    
    public Hashtable execute(MMAGrid grid, MMATimeCube tCube) throws MMAFunctionInitException    
    {        
        //grid = initGrid1();
        //tCube = initTimeCube1();
        ZonalLoop zonalobj = new ZonalLoop();
        Hashtable ht_multiple_val = zonalobj.loopGrid_TimeCube(grid, tCube);    
        ZonalFunctions funcobj = new ZonalFunctions();
        Hashtable ht_single_val = funcobj.calculateZonalAdd(ht_multiple_val);
        return ht_single_val;        
    }
    
    public Hashtable execute(MMAGrid grid, MMASpaceCube sCube) throws MMAFunctionInitException    
    {        
        //grid = initGrid1();
        //sCube = initSpaceCube1();        
        ZonalLoop zonalobj = new ZonalLoop();
        Hashtable ht_multiple_val = zonalobj.loopGrid_SpaceCube(grid, sCube);    
        ZonalFunctions funcobj = new ZonalFunctions();
        Hashtable ht_single_val = funcobj.calculateZonalAdd(ht_multiple_val);
        return ht_single_val;        
    }

    public Hashtable execute(MMAGrid grid, MMAHyperCube hCube) throws MMAFunctionInitException    
    {        
        //grid = initGrid1();
        //hCube = initHyperCube1();                
        ZonalLoop zonalobj = new ZonalLoop();
        Hashtable ht_multiple_val = zonalobj.loopGrid_HyperCube(grid, hCube);    
        ZonalFunctions funcobj = new ZonalFunctions();
        Hashtable ht_single_val = funcobj.calculateZonalAdd(ht_multiple_val);
        return ht_single_val;                
    }
    
    public Hashtable execute(MMASpaceCube sCube1, MMASpaceCube sCube2) throws MMAFunctionInitException    
    {
        //sCube1 = initSpaceCube1();
        //sCube2 = initSpaceCube2();        
        ZonalLoop zonalobj = new ZonalLoop();
        Hashtable ht_multiple_val = zonalobj.loopSpaceCube_SpaceCube(sCube1, sCube1);    
        ZonalFunctions funcobj = new ZonalFunctions();
        Hashtable ht_single_val = funcobj.calculateZonalAdd(ht_multiple_val);
        return ht_single_val;                                
    }
    
    public Hashtable execute(MMASpaceCube sCube, MMAHyperCube hCube) throws MMAFunctionInitException    
    {        
        sCube = initSpaceCube1();
        hCube = initHyperCube1();
        ZonalLoop zonalobj = new ZonalLoop();
        Hashtable ht_multiple_val = zonalobj.loopSpaceCube_HyperCube(sCube, hCube);    
        ZonalFunctions funcobj = new ZonalFunctions();
        Hashtable ht_single_val = funcobj.calculateZonalAdd(ht_multiple_val);
        return ht_single_val;                                
    }

    public Hashtable execute(MMATimeCube tCube1, MMATimeCube tCube2) throws MMAFunctionInitException    
    {
        //tCube1 = initTimeCube1();
        //tCube2 = initTimeCube2();        
        ZonalLoop zonalobj = new ZonalLoop();
        Hashtable ht_multiple_val = zonalobj.loopTimeCube_TimeCube(tCube1, tCube2);    
        ZonalFunctions funcobj = new ZonalFunctions();
        Hashtable ht_single_val = funcobj.calculateZonalAdd(ht_multiple_val);
        return ht_single_val;                                
    }

    public Hashtable execute(MMATimeCube tCube, MMAHyperCube hCube) throws MMAFunctionInitException    
    {        
        //tCube = initTimeCube1();
        //hCube = initHyperCube1();        
        ZonalLoop zonalobj = new ZonalLoop();
        Hashtable ht_multiple_val = zonalobj.loopTimeCube_HyperCube(tCube, hCube);    
        ZonalFunctions funcobj = new ZonalFunctions();
        Hashtable ht_single_val = funcobj.calculateZonalAdd(ht_multiple_val);
        return ht_single_val;                                        
    }
    
    public Hashtable execute(MMAHyperCube hCube1, MMAHyperCube hCube2) throws MMAFunctionInitException    
    {        
        //hCube1 = initHyperCube1();
        //hCube2 = initHyperCube2();        
        ZonalLoop zonalobj = new ZonalLoop();
        Hashtable ht_multiple_val = zonalobj.loopHyperCube_HyperCube(hCube1, hCube2);
        ZonalFunctions funcobj = new ZonalFunctions();
        Hashtable ht_single_val = funcobj.calculateZonalAdd(ht_multiple_val);
        return ht_single_val;                                               
    }    
}
